package company.aqiyi;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-09-15 10:43
 */
public class A1 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String input = scanner.next();
            int[] array = new int[6];
            for (int i = 0; i < 6; i++) {
                array[i] = input.charAt(i) - '0';
            }

            System.out.println(helper(array));

        }
    }


    public static int helper(int[] array) {
        int left = 0, right = 0;
        Arrays.sort(array, 0, 3);
        Arrays.sort(array, 3, 6);


        for (int i = 0; i < 3; i++) {
            left += array[i];
            right += array[5 - i];

        }
        int res = 0;
        if (left == right) return res;
        if (left > right){
            left = left + right;
            right = left - right;
            left = left -right;
            swap(array);
        }

        int leftIndex = 0,rightIndex = 5;

        while (leftIndex <3 && rightIndex >=3 && left < right){
            int add = 9 - array[leftIndex];
            int decrease = array[rightIndex];
            if (add > decrease){
                left += add;
                res++;
                leftIndex++;
            }else {
                right -= decrease;
                res++;
                rightIndex--;
            }


        }

        return res;


    }

    private static void swap(int[] array) {
        for (int i = 0; i < 3; i++) {
            int temp = array[i];
            array[i] = array[i+3];
            array[i+3] = temp;
        }
    }
}
